package com.zhouyu.mybatis.config;

import com.zhouyu.mybatis.mybatis.MybatisMapperScan;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author by gang.Li 2022/4/7 13:39
 */
@Configuration
@ComponentScan("com.zhouyu.mybatis")
@MybatisMapperScan("com.zhouyu.mybatis.mapper")
public class AppConfig {

	@Bean
	public SqlSessionFactory sqlSessionFactory() throws IOException {
		InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
		return new SqlSessionFactoryBuilder().build(resourceAsStream);
	}
}
